{extends file="../acp.html"}

{block name="title"}{$head_title}{/block}
{block name="content"}
<div class="tablesWrap">
<!--    <div class="tables-searchbox">
        <form method="post">
            <span class="tbs-txt">企业名称：</span>
            <input type="text" name="company_name" value="{$company_name}">

             <span class="tbs-txt">退押金时间：</span>
             <input type="text" autocomplete="off" class="Wdate" name="start_date" value="{$start_date|date_format:'%Y-%m-%d %H:%M'}"  onclick="WdatePicker({ dateFmt:'yyyy-MM-dd HH:mm'})">
             <span class="tbs-txt">至</span>
             <input type="text" autocomplete="off" class="Wdate" name="end_date" value="{$end_date|date_format:'%Y-%m-%d %H:%M'}"  onclick="WdatePicker({ dateFmt:'yyyy-MM-dd HH:mm'})">


            <select name="is_out" class="small">
                <option value="-1" selected="">-押金是否已退-</option>
                <option value="0" {if $is_out == 0 } selected{/if}>否</option>
                <option value="1" {if $is_out == 1 } selected{/if}>是</option>
            </select>

            <select name="is_receipt" class="small">
                <option value="-1" selected="">-收据是否已开-</option>
                <option value="0" >否</option>
                <option value="1" >是</option>
            </select>


            <button type="submit" class="btn"><i class="gicon-search"></i>搜索</button>
        </form>
    </div>-->
<!-- end tables-searchbox -->  
<table class="wxtables">  
    <colgroup>  
    <!--<col width="6%">-->
    <col width="10%">
    <col width="10%">
    <col width="10%">
    <col width="10%">
    <col width="10%">
    <col width="10%">
    <col width="10%">
    <col width="10%">
    </colgroup>
    <thead>
        <tr>
            <!--<td>选择</td>-->
            <td>企业名称</td>
            <td>联系人</td>
            <td>联系方式</td>
            <td>租凭总金额</td>
            <td>已收租金</td>
            <td>未收租金</td>
            <td>逾期总租金</td>
            <td>租金状态</td>
            <td>操作</td>
        </tr>  
    </thead>  
	{foreach from=$contract_list item=this}
    <tbody class="combo-tbody">  
        <tr>
            <!--<td><input type="checkbox" class="checkbox" value="{$item.item_id}" name="checkIds[]"></td>-->
			<td>{$this.company_name}</td>
			<td>{$this.linkman}</td>
			<td>{$this.link_way}</td>
			<td>{$this.total_money}</td>
			<td>{$this.total_actual_money}</td>
			<td>{$this.total_goat_money}</td>
			<td>{$this.total_overdue_money}</td>
			<td>{$this.state}</td>
            <td>
                {if $this.state != '结清'}
				<a href="javascript:;" class="btn add_rent" data-contract_id="{$this.contract_id}" title="押金登记">收租登记</a>
                {/if}
                <a href="/AcpContract/get_rent_details_list/contract_id/{$this.contract_id}" class="btn"  title="查看明细">查看明细</a>
            </td>  
        </tr>
    </tbody>
	{foreachelse}   
    <tbody>    
		<tr>
			<td colspan="7">
				没有符合条件的记录
			</td>
		<tr>
    </tbody>  
	{/foreach}
</table>  
<!-- end wxtables -->  
<div class="tables-btmctrl clearfix">  
    <!--<div class="fl">  -->
        <!--<a href="javascript:;" class="btn btn-blue" onclick="Select()">全选</a>  -->
        <!--<a href="javascript:;" class="btn btn-blue" onclick="Cancel()">取消</a>  -->
        <!--<a href="javascript:;" onclick="batch_delete()" class="btn btn-blue">删除</a>-->
    <!--</div>  -->
    <div class="fr">  
        <div class="paginate">
			{$page_str} 
        </div>  
        <!-- end paginate -->  
    </div>  
</div>  
<!-- end tables-btmctrl -->  
</div>

<!--<div class="formitems inline">
    <label class="fi-name">期次：</label>
</div>

<div class="formitems inline">
    <label class="fi-name">交租日期：</label>
    <div class="form-controls">
        <input type="text" autocomplete="off" class="Wdate data_th"  name="rent_time" id="rent_time" value=""><span class="fi-help-text">不填则为当前日期 </span>
    </div>
</div>

<div class="formitems inline">
    <label class="fi-name"><span class="colorRed">*</span>本期应交金额：</label>
    <div class="form-controls">
        <input name="payable_money" id="payable_money" disabled><span class="fi-help-text"></span>
    </div>
</div>

<div class="formitems inline">
    <label class="fi-name"><span class="colorRed">*</span>本期应缴逾期金额：</label>
    <div class="form-controls">
        <input name="overdue_money" id="overdue_money" disabled><span class="fi-help-text"></span>
    </div>
</div>

<div class="formitems inline">
    <label class="fi-name"><span class="colorRed">*</span>实交金额：</label>
    <div class="form-controls">
        <input name="actual_money" id="actual_money" ><span class="fi-help-text"></span>
    </div>
</div>

<div class="formitems inline">
    <label class="fi-name">实际交付日期：</label>
    <div class="form-controls">
        <input type="text" autocomplete="off" class="Wdate data_th"  name="actual_time" id="actual_time" value=""><span class="fi-help-text">不填则为当前日期 </span>
        </div>
    </div>-->
<!-- end tablesWrap -->   
{/block} 

{block name="js"}
<script src="/Public/Plugins/My97DatePicker/WdatePicker.js?version={$version}"></script>
<script src="__JS__/clipboard.min.js"></script>
{literal}
<script>
	//全选
	function Select(){
		var sel=document.getElementsByName("a[]");
		for(var i=0;i<sel.length;i++){
			sel[i].checked=true;
		}
	}
	//取消全选
	function Cancel(){
		var sel=document.getElementsByName("a[]");
		for(var i=0;i<sel.length;i++){
			sel[i].checked=false;
		}
	}

function delete_service_type(type_id)
{
	$.jPops.confirm(
	{  
		 title:"提示",  
		 content:"您确定要删除这条数据吗？",  
		 okBtnTxt:"确定",  
		 cancelBtnTxt:"取消",  
		 callback:function(r)
		 {  
			 if(r)
			 {
				 $.post('/AcpSiteType/delete_site_type', {"type_id":type_id}, function(data, textStatus)
				 {
					if (data == 'success')
					{
						alert('恭喜您，删除成功！');
						location.reload();
					}
					else
					{
						alert('对不起，场地类型下存在场地，删除失败！');
					}
				});
			 }  
			 return true;  
		 }
	 });  	
}

function batch_delete()
{
	$.jPops.confirm(
	{  
		 title:"提示",  
		 content:"您确定要删除这些数据吗？",  
		 okBtnTxt:"确定",  
		 cancelBtnTxt:"取消",  
		 callback:function(r)
		 {  
			 if(r)
			 {
				 var type_ids = '';
				 var count = 0;
				 $('input[name="a[]"]:checked').each(function(){
					 count ++;
                     type_ids += $(this).val() + ',';
				 });

				 if (!count)
				 {
					 alert('对不起，请选择至少一项进行删除！');
					 return;
				 }

                 type_ids = type_ids.substr(0, type_ids.length - 1);

				 $.post('/AcpSiteType/batch_delete_site_type', {"type_ids":type_ids}, function(data, textStatus)
				 {
					if (data == 'success')
					{
						alert('恭喜您，删除成功！');
						location.reload();
					}
					else
					{
						alert('对不起，场地类型下存在场地，删除失败！');
					}
				});
			 }  
			 return true;  
		 }
	 });
}
//复制商品链接
function class_link(class_id)
{
    var link = 'http://' + document.domain + '/FrontMall/item_list/class_id/' + class_id;
    $.jPops.custom({
        title:"请复制链接",  
        content:'<div>一级分类链接：' + link + '</div>',
        okBtnTxt:"复制",  
        cancelBtnTxt:"关闭",  
        callback:function(r)
        {
            if(r)
            {
                text = link;
                copy_text('jpops-btn-ok');
            }
            else
            {
                return true;  
            }
        }
    });
}
function copy_text(id)
    {
        var clipboard = new Clipboard('#' + id, {
            text: function() {
                return text;
            }
        });

        clipboard.on('success', function(e) {
            console.log(e);
            alert('复制成功');
        });

        clipboard.on('error', function(e) {
            console.log(e);
            alert('复制失败，请手动复制');
        });
    }

    var num = 0;
    var payable_money = 0;
    var overdue_money = 0;
    //收租登记
    $("body").on("click",".data_th",function(){
        WdatePicker({ dateFmt:'yyyy-MM-dd HH:mm'});
    })
    $('.add_rent').on("click",function(){

        var contract_id=$(this).attr('data-contract_id');
        $.ajax({
            type:'post',
            async:false,
            url:'/AcpContract/get_payable_overdue_money',
            data:{contract_id:contract_id},
            success:function (r) {
                     num = r.count;
                     payable_money = r.payable_money;
                     overdue_money = r.overdue_money;
            }
        })

        var html='<form id="add_rent_form">\
                <div class="formitems inline">\
                <label class="fi-name">期次：'+num+'</label>\
                </div>\
                <div class="formitems inline">\
                <label class="fi-name">交租日期：</label>\
                <div class="form-controls">\
                <input type="text" autocomplete="off" class="Wdate data_th"  name="rent_time" id="rent_time" value=""><span class="fi-help-text">不填则为当前日期 </span>\
                </div>\
                </div>\
                <div class="formitems inline">\
                <label class="fi-name"><span class="colorRed">*</span>本期应交金额：</label>\
                <div class="form-controls">\
                <input name="payable_money" id="payable_money" value="'+payable_money+'" readonly><span class="fi-help-text"></span>\
                </div>\
                </div>\
                <div class="formitems inline">\
                <label class="fi-name"><span class="colorRed">*</span>本期应缴逾期金额：</label>\
        <div class="form-controls">\
                <input name="overdue_money" id="overdue_money" value="'+overdue_money+'" readonly><span class="fi-help-text"></span>\
                </div>\
                </div>\
                <div class="formitems inline">\
                <label class="fi-name"><span class="colorRed">*</span>实交金额：</label>\
        <div class="form-controls">\
                <input name="actual_money" id="actual_money" ><span class="fi-help-text"></span>\
                </div>\
                </div>\
                <div class="formitems inline">\
                <label class="fi-name">实际交付日期：</label>\
        <div class="form-controls">\
                <input type="text" autocomplete="off" class="Wdate data_th"  name="actual_time" id="actual_time" value=""><span class="fi-help-text">不填则为当前日期 </span>\
                </div>\
                </div>\
                <input type="hidden" name="contract_id" value="'+contract_id+'" />\
                </form>';

        $.jPops.custom({
            title:"押金登记",
            content:html,
            okBtnTxt:"确定",
            cancelBtnTxt:"取消",
            callback:function(r)
            {
                if(r){
                    $.validator.setDefaults(
                            {
                                //表单验证通过后的处理，异步提交表单
                                submitHandler: function()
                                {
                                    $.post('/AcpContract/add_rent',$('form').serialize(),function(data)
                                    {
                                        console.log(data);
                                        if (data == 1 )
                                        {
                                            alert(data.msg);
                                            location.reload();
                                        }else{
                                            alert(data.msg);
                                        }
                                    })
                                    acp.batchDeliverFormStatus = true;
                                }
                            });

                    $("#add_rent_form").validate(
                            {
                                rules:
                                {
                                    actual_money:
                                    {
                                        required: true,
                                        number:true
                                    },
                                },
                                messages:
                                {
                                    actual_money:
                                    {
                                        required: "对不起，请填写实交金额",
                                        number: "请填写数字!"
                                    },
                                },
                                errorPlacement: acp.form_ShowError,//显示出错信息(这段代码必须加)
                                success:acp.form_HideError//验证成功隐藏错误信息(这段代码必须加)
                            });

                    //模拟提交表单
                    $("#add_rent_form").submit();
                    return acp.batchDeliverFormStatus;
                }else{
                    return true;
                }
            }

        });
    })
</script>
{/literal}
{/block} 

{block name="css"}
<link type="text/css" rel="stylesheet" href="__ACPCSS__/tip.css" />
{literal}
<style>
.PageNext{page-break-after: always; height:1px;}
</style>
{/literal}
{/block} 
